from collections import namedtuple

"""
sample plugins:
rss-feed
file/directory changed
svn, bazar, ... commit
web site changed
new mail
new process, load, ram, disk
log file
im message
ftp / sftp file changed
"""
########################################
## Abstract classes
########################################
Item = namedtuple('Item', 'title content author date')

class GenericEventLoader(object):
    """Abstract class: must be pickable ! Do not use instance method nor file attribute"""
    event_type = "Generic"
    def __init__(self,config):
        self.config = config
        self.title = config['title']
        self.recursion = None #must be a rrule or rruleset instance
        self.cache = None #use this for caching (must be comparable!!!!)
        self.errors = "" # status of event loader (example: ok, errors . . .)

    def getItems(self):
        """returns a list of items - remove eventually duplicates (using self.cache)

can raise an exception"""
        raise NotImplementedError

    def __eq__(self,other):
        """required by sqlalchemy"""
        if type(other)!=type(self): return False
        return self.config == other.config and self.cache == other.cache and self.errors == other.errors

    def isDead(self):
        """returns True if the event factory is dead and the event factory must be deleted"""
        return self.recursion.after(datetime.now) == None

    def __repr__(self):
        return self.title
